package org.sergiy.metawidget.rules;

import java.util.Arrays;
import java.util.List;

import org.metawidget.inspector.impl.BaseObjectInspectorConfig;

/**
 * Configuration for Business rules based inspector
 * 
 * @author Sergiy Litsenko
 *
 */
public class BusinessRulesInspectorConfig extends BaseObjectInspectorConfig {
	// DROOLS source files 
	private List<Object> droolsSourceFiles;
	
	/**
	 * Default constructor
	 */
	public BusinessRulesInspectorConfig() {
		super();
	}

	/**
	 * Constructor
	 * @param droolsSourceFiles
	 */
	public BusinessRulesInspectorConfig(List<Object> droolsSourceFiles) {
		this();
		setDroolsSourceFiles(droolsSourceFiles);
	}

	/**
	 * Constructor
	 * @param droolsSourceFiles
	 */
	public BusinessRulesInspectorConfig(Object... droolsSourceFiles) {
		this(Arrays.asList(droolsSourceFiles));
	}
	
	/**
	 * Get DROOLS source files
	 * @return the droolsSourceFiles
	 */
	public List<Object> getDroolsSourceFiles() {
		return droolsSourceFiles;
	}

	/**
	 * Sets DROOLS source files
	 * @param droolsSourceFiles the droolsSourceFiles to set
	 */
	public void setDroolsSourceFiles(List<Object> droolsSourceFiles) {
		this.droolsSourceFiles = droolsSourceFiles;
	}

	/**
	 * Sets DROOLS source files
	 * @param droolsSourceFiles array
	 */
	public void setDroolsSourceFiles(Object... droolsSourceFiles) {
		setDroolsSourceFiles (Arrays.asList(droolsSourceFiles));
	}
	
	/* (non-Javadoc)
	 * @see java.lang.Object#hashCode()
	 */
	@Override
	public int hashCode() {
		final int prime = 31;
		int result = super.hashCode();
		result = prime
				* result
				+ ((droolsSourceFiles == null) ? 0 : droolsSourceFiles
						.hashCode());
		return result;
	}

	/* (non-Javadoc)
	 * @see java.lang.Object#equals(java.lang.Object)
	 */
	@Override
	public boolean equals(Object obj) {
		if (this == obj) {
			return true;
		}
		if (!super.equals(obj)) {
			return false;
		}
		if (!(obj instanceof BusinessRulesInspectorConfig)) {
			return false;
		}
		BusinessRulesInspectorConfig other = (BusinessRulesInspectorConfig) obj;
		if (droolsSourceFiles == null) {
			if (other.droolsSourceFiles != null) {
				return false;
			}
		} else if (!droolsSourceFiles.equals(other.droolsSourceFiles)) {
			return false;
		}
		return true;
	}

	/* (non-Javadoc)
	 * @see java.lang.Object#toString()
	 */
	@Override
	public String toString() {
		return String.format(
				"BusinessRulesInspectorConfig [droolsSourceFiles=%s]",
				droolsSourceFiles);
	}

}
